﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Xml;
using Enter.Mvc.Base.Model;

namespace MyChy.Mvc.Base.Service
{
	internal class UnityBaseConfigManager : IConfigurationSectionHandler
	{
		public object Create(object parent, object configContext, System.Xml.XmlNode section)
		{
			UnityBase setting = new UnityBase();
			if (section != null)
			{
				foreach (XmlNode xn in section.ChildNodes)
				{
					switch (xn.Name)
					{
						case "CssPath":
							if (!string.IsNullOrEmpty(xn.InnerText))
							{
								setting.CssPath = string.Format("/Content/{0}/", xn.InnerText);
							}
							else
							{
								setting.CssPath = string.Format("/Content/");
							}
							break;
						case "CssImagePath":
							if (!string.IsNullOrEmpty(xn.InnerText))
							{
								setting.ImagePath = string.Format("{0}{1}/", setting.CssPath, xn.InnerText);
							}
							else
							{
								setting.ImagePath = setting.CssPath;
							}
							
							break;
						case "Description":
							setting.Description = xn.InnerText;
							break;
						case "Keywords":
							setting.Keywords = xn.InnerText;
							break;
						case "PageTitleSeparator":
							setting.PageTitleSeparator = xn.InnerText;
							break;
						case "ScriptsPath":
							setting.ScriptsPath = xn.InnerText;
							break;
						case "SkinDefault":
							setting.SkinDefault = xn.InnerText;
							break;
						case "Webname":
							setting.Webname = xn.InnerText;
							break;
						case "Website":
							setting.Website = xn.InnerText;
							break;
					}
				}
			}

			return setting;
		}
	}
}
